﻿using AutoMapper;
using ManagementApi.Models;
using ManagementApi.Models.Manage.ProjectSpecialAccount;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Modules.BankSpecialAccount;
using Modules.BankSpecialAccount.Entitys;
using PmSoft.ApplicationContext;

namespace ManagementApi.Controllers.AdminPannel
{
    /// <summary>
    /// 项目管理员-收支信息
    /// </summary>
    [Route("/api/v1/sysuser/projectspecialaccountpayment")]
    [ApiController]
    [Authorize(Roles = "SysUser")]
    public class ProjectSpecialAccountPaymentController : ControllerBase
    {
        private readonly BankSpecialAccountPaymentService projectSpecialAccountPaymentService;
        private readonly IApplicationContext applicationContext;
        private readonly IMapper mapper;

        /// <summary>
        /// 专户管理控制器
        /// </summary>
        /// <param name="projectSpecialAccountPaymentService"></param>
        /// <param name="applicationContext"></param>
        /// <param name="mapper"></param>
        public ProjectSpecialAccountPaymentController(BankSpecialAccountPaymentService projectSpecialAccountPaymentService, IApplicationContext applicationContext, IMapper mapper)
        {
            this.projectSpecialAccountPaymentService = projectSpecialAccountPaymentService;
            this.applicationContext = applicationContext;
            this.mapper = mapper;
        }

        ///// <summary>
        ///// author:hzj date:2023/11/8 describe:添加专户收支信息
        ///// </summary>
        ///// <param name="id"></param>
        ///// <param name="form"></param>
        ///// <returns></returns>
        //[HttpPost("create")]
        //[PermissionCheck("sys:specialaccount_payment:add")]
        //public ApiResult ProjectSpecialAccountPayment(ProjectSpecialAccountPaymentEditForm form)
        //{
        //    ProjectSpecialAccountPayment entity = new();
        //    mapper.Map(form, entity);
        //    entity.CreateTime = DateTime.Now;
        //    projectSpecialAccountPaymentService.CreateProjectSpecialAccountPayment(entity);
        //    return ApiResult.Success("创建成功");
        //}

        ///// <summary>
        ///// author:hzj date:2023/11/8 describe:修改收支信息
        ///// </summary>
        ///// <param name="id"></param>
        ///// <param name="form"></param>
        ///// <returns></returns>
        //[HttpPut("{id}")]
        //[PermissionCheck("sys:specialaccount_payment:update")]
        //public ApiResult UpdateProjectSpecialAccountPaymentStatus(int id, ProjectSpecialAccountPaymentEditForm form)
        //{
        //    ProjectSpecialAccountPayment? data = projectSpecialAccountPaymentService.GetProjectSpecialAccountPayment(id);
        //    if (data == null) return ApiResult.Failure("收支信息不存在");
        //    mapper.Map(form, data);
        //    projectSpecialAccountPaymentService.UpdateProjectSpecialAccountPayment(data);
        //    return ApiResult.Success("修改成功");
        //}

        /// <summary>
        /// author:hzj date:2023/11/8 describe:获取指定收支信息
        /// </summary>
        /// <param name="id">角色ID</param>
        /// <returns></returns>
        [HttpGet("{id}/form")]
        public ApiResult<ProjectSpecialAccountPaymentDto> GetProjectSpecialAccountPayment(int id)
        {
            BankSpecialAccountPayment? data = projectSpecialAccountPaymentService.GetProjectSpecialAccountPayment(id);
            if (data == null)
                return ApiResult<ProjectSpecialAccountPaymentDto>.Failure("收支信息不存在");
            return ApiResult<ProjectSpecialAccountPaymentDto>.Success(data.AsProjectSpecialAccountPaymentDto(applicationContext));
        }

        /// <summary>
        /// author:hzj date:2023/11/8 describe:获取收支信息列表
        /// </summary>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页数量</param>
        /// <returns></returns>
        [HttpGet("page")]
        public ApiResult<PageDto<ProjectSpecialAccountPaymentDto>> GetProjectSpecialAccountPayments([FromQuery] BankSpecialAccountPaymentQuery query, int pageNum = 1, int pageSize = 20)
        {
            var data = projectSpecialAccountPaymentService.GetProjectSpecialAccountPayments(query, pageNum, pageSize);
            var dtos = data.AsPageDto(source => { return source.AsProjectSpecialAccountPaymentDto(applicationContext); });
            return ApiResult<PageDto<ProjectSpecialAccountPaymentDto>>.Success(dtos);
        }

        ///// <summary>
        ///// author:hzj date:2023/11/8 describe:删除收支信息
        ///// </summary>
        ///// <param name="ids"></param>
        ///// <returns></returns>
        //[HttpDelete("{ids}")]
        //[PermissionCheck("sys:specialaccount_payment:delete")]
        //public ApiResult Delete(string ids)
        //{
        //    projectSpecialAccountPaymentService.DeletProjectSpecialAccountPayments(ValueUtility.ConvertToList<int>(ids));
        //    return ApiResult.Success("删除成功");
        //}
    }
}